﻿using CodeMonkey.EditableObject.Attributes;
using CodeMonkey.EditableObject.Core;
using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace WpfApplication1
{
    [Serializable]
    public class Contact : ObservableObject
    {
        public Contact(int id)
        {
            this.ID = id;
        }
        public int ID { get; private set; }

        private string title = default(string);
        //[TransactionAttribute(false)] //可以尝试反注释掉该行和EditableTypeDescriptor构造函数中的行 看看效果
        public string Title
        {
            get { return title; }
            set { Set("Title", ref title, value); }
        }


        private string firstName = default(string);
        public string FirstName
        {
            get { return firstName; }
            set { Set("FirstName", ref firstName, value); }
        }


        private string lastName = default(string);
        public string LastName
        {
            get { return lastName; }
            set { Set("LastName", ref lastName, value); }
        }

        private double age = default(double);
        public double Age
        {
            get
            {
                return age;
            }
            set { Set("Age", ref age, value); }
        }


        private double ageLarge = default(double);
        public double AgeLarge
        {
            get { return ageLarge; }
            set { Set("AgeLarge", ref ageLarge, value); }
        }


        private DateTime birthDate = default(DateTime);

        //[AffectsOtherProperty("Age")]
        public DateTime BirthDate
        {
            get { return birthDate; }
            set
            {
                if (Set("BirthDate", ref birthDate, value))
                {
                    //// Calculate their age
                    //var today = DateTime.Now;
                    //int age = today.Year - this.BirthDate.Year;

                    //// Have they had their birthday yet this year? 判断是否满一年;如果不满,则减去一
                    //var birthDayThisYear = new DateTime(today.Year, this.BirthDate.Month, this.BirthDate.Day);
                    //bool hadBirthdayThisYear = (today >= birthDayThisYear);

                    //// If they haven't had their birthday yet this year then they are actually 1 year younger
                    //// than our initial calculation suggested
                    //if (!hadBirthdayThisYear)
                    //    age -= 1;

                    //Age = age;
                }
            }
        }


        private Sexy sexy = default(Sexy);
        public Sexy Sexy
        {
            get { return sexy; }
            set { Set("Sexy", ref sexy, value); }
        }


        private Grade grade = default(Grade);
        public Grade Grade
        {
            get { return grade; }
            set { Set("Grade", ref grade, value); }
        }

    }


    public class ContactNew
    {

        public ContactNew(int id)
        {
            ID = id;
        }
        public int ID { get; private set; }
        public string Title { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public DateTime BirthDate { get; set; }
        public int Age { get; set; }
        public int AgeLarge { get; set; }
        public Sexy Sexy { get; set; }
        public Grade Grade { get; set; }
    }


    public enum Sexy
    {
        [Description("男")]
        Man,
        [Description("女")]
        Women
    }

    public enum Grade
    {
        [Description("大")]
        Big,
        [Description("中")]
        Middle,
        [Description("小")]
        Small

    }

}
